package com.rslai.base.tool.servertest.reporter;

import com.rslai.base.tool.servertest.Statistics;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ParseCase
        implements Runnable {
    private QJSONReporter reporter;
    private Map<Object, Object> element;

    public ParseCase(QJSONReporter reporter, Map<Object, Object> element) {
        this.reporter = reporter;
        this.element = element;
    }

    public void run() {
        String name = (String) this.element.get("name");
        boolean result = parse();
        if (result)
            this.reporter.addSuccess();
        else {
            this.reporter.addFailed(name);
        }
        Statistics.start(this.reporter.getCaseStatistics());
    }

    private boolean parse() {
        List steps = (List) this.element.get("steps");
        for (Iterator i$ = steps.iterator(); i$.hasNext(); ) {
            Object object = i$.next();
            Map result = (Map) ((Map) object).get("result");
            if ("failed".equalsIgnoreCase((String) result.get("status"))) {
                return false;
            }
        }
        return true;
    }
}
